package com.esurvey.core;
import java.util.ArrayList;

public class Question {
	private int id;
	private int idSurvey;
	private String question;
	private QuestionKind kind;
	private ArrayList<Answer> answers;

	public Question(String question, String kind, ArrayList<Answer> answers) throws Exception {
		this.setQuestion(question);
		this.setKind(kind);
		this.setAnswers(answers);
	}
	
	private Question(int idSurvey, String question, ArrayList<Answer> answers) {
		this.setIdSurvey(idSurvey);
		this.setQuestion(question);
		this.setAnswers(answers);
	}
	
	private Question(int id, int idSurvey, String question, ArrayList<Answer> answers) {
		this(idSurvey, question, answers);
		this.setId(id);
	}
	
	public Question(int idSurvey, String question, String kind, ArrayList<Answer> answers) throws Exception {
		this(idSurvey, question, answers);
		this.setKind(kind);
	}
	
	public Question(int idSurvey, String question, QuestionKind kind, ArrayList<Answer> answers) {
		this(idSurvey, question, answers);
		this.setKind(kind);
	}
	
	public Question(int id, int idSurvey, String question, String kind, ArrayList<Answer> answers) throws Exception {
		this(id, idSurvey, question, answers);
		this.setKind(kind);
	}
	
	public Question(int id, int idSurvey, String question, QuestionKind kind, ArrayList<Answer> answers) {
		this(id, idSurvey, question, answers);
		this.setKind(kind);
	}
	
	

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}
	
	public void setIdSurvey(int idSurvey) {
		this.idSurvey = idSurvey;
	}

	public int getIdSurvey() {
		return idSurvey;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	public String getQuestion() {
		return question;
	}

	public void setKind(QuestionKind kind) {
		this.kind = kind;
	}
	
	public void setKind(String kind) throws Exception {
		if ((kind.toUpperCase().equals("RESPUESTA ABIERTA")) || (kind.toUpperCase().equals("RESPUESTA_ABIERTA"))) {
			this.kind = QuestionKind.RESPUESTA_ABIERTA;
		} else if (kind.toUpperCase().equals("MONORESPUESTA")) {
			this.kind = QuestionKind.MONORESPUESTA;
		} else if (kind.toUpperCase().equals("MULTIRESPUESTA")) {
			this.kind = QuestionKind.MULTIRESPUESTA;
		} else {
			throw new eSurveyException("Cannot setKind("+kind+ "): invalid value");
		}
	}
	
	public String getKindToString() throws Exception {
		if (kind.equals(QuestionKind.RESPUESTA_ABIERTA)) {
			return "Respuesta abierta";
		} else if (kind.equals(QuestionKind.MONORESPUESTA)) {
			return "Monorespuesta";
		} else if (kind.equals(QuestionKind.MULTIRESPUESTA)) {
			return "Multirespuesta";
		} else {
			throw new eSurveyException("Cannot getKindToString(): invalid value "+kind.toString());
		}
	}

	public QuestionKind getKind() {
		return kind;
	}

	public void setAnswers(ArrayList<Answer> answers) {
		this.answers = answers;
	}

	public ArrayList<Answer> getAnswers() {
		return answers;
	}
}
